package com.lucien.framework.exception;

import com.lucien.common.constant.HttpStatus;
import com.lucien.common.result.GlobalResult;
import org.apache.shiro.authz.UnauthenticatedException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @Author: Lucien
 * @Description: 异常处理类
 * @Date: Created in 2021/5/3
 */
@ControllerAdvice
public class AllException {

    @ExceptionHandler
    public GlobalResult exceptiona(Exception ex) {
        if(ex instanceof UnauthenticatedException) {
            return GlobalResult.error(HttpStatus.UNAUTHORIZED,"请先登录");
        }
        else if(ex instanceof UnauthorizedException) {
            return GlobalResult.error(HttpStatus.FORBIDDEN,"您没有管理员权限");
        }
        else if(ex instanceof Exception){
            return GlobalResult.error();
        }
        return null;
    }

}
